package com.api.shopapi.mapper;

import com.api.shopapi.entity.ConsultRecord;
import com.api.shopapi.entity.dto.ConsultRecordDTO;
import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Repository;

import java.util.List;

@Mapper
@Repository
public interface ConsultRecordMapper {

    @Insert("insert into consult_record (ConsultRecordCode,UserCode,Question,QuestionTime,StaffCode,Reply,ReplyTime,Status,GovernmentCode) " +
            "values (#{consultRecord.ConsultRecordCode},#{consultRecord.UserCode},#{consultRecord.Question}," +
            "#{consultRecord.QuestionTime},#{consultRecord.StaffCode},#{consultRecord.Reply},#{consultRecord.ReplyTime},#{consultRecord.Status},#{consultRecord.GovernmentCode})")
    int insert(@Param("consultRecord") ConsultRecord consultRecord);

    @Update("update consult_record set UserCode=#{consultRecord.UserCode},Question=#{consultRecord.Question}," +
            "QuestionTime=#{consultRecord.QuestionTime},StaffCode=#{consultRecord.StaffCode},Reply=#{consultRecord.Reply}," +
            "ReplyTime=#{consultRecord.ReplyTime},Status=#{consultRecord.Status},GovernmentCode=#{consultRecord.GovernmentCode} " +
            "where ConsultRecordCode=#{consultRecord.ConsultRecordCode}")
    int update(@Param("consultRecord") ConsultRecord consultRecord);

    @Select("select * from consult_record where ConsultRecordCode=#{consultRecordCode}")
    ConsultRecord getByConsultRecordCode(@Param("consultRecordCode") String consultRecordCode);

    @Select("<script>" +
            "select * from consult_record where GovernmentCode=#{governmentCode} "+
            "<if test ='status!=-1 '>" +
            " and Status=#{status} " +
            "</if>" +
            "and QuestionTime between #{startTime} and #{endTime} " +
            "order by QuestionTime desc" +
            "</script>")
    List<ConsultRecordDTO> getPageAdm(@Param("startTime") String startTime,@Param("endTime") String endTime,
                                   @Param("status") int status,@Param("governmentCode")String governmentCode);

    @Select("<script>" +
            "select * from consult_record where UserCode=#{userCode} "+
            "<if test ='status!=-1 '>" +
            " and Status=#{status} " +
            "</if>" +
            "order by QuestionTime desc" +
            "</script>")
    List<ConsultRecordDTO> getPageApp( @Param("status") int status,@Param("userCode")String userCode);



}
